package com.qumitech.visualnovel.service.novel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.List;

import com.qumitech.visualnovel.model.common.BaseResponse;
import com.qumitech.visualnovel.model.dao.console.RoleDAO;
import com.qumitech.visualnovel.datasource.editor.RoleDAOMapper;
import com.qumitech.visualnovel.model.dto.RoleAddDTO;
import com.qumitech.visualnovel.model.dto.RoleUpdateDTO;
import com.qumitech.visualnovel.model.dto.RoleQueryDTO;

@Slf4j
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleDAOMapper roleDAOMapper;

    @Override
    public BaseResponse create(RoleAddDTO body) {
        RoleDAO record = new RoleDAO();
        body.assignTo(record);
        roleDAOMapper.insertSelective(record);
        return new BaseResponse();
    }

    @Override
    public BaseResponse update(RoleUpdateDTO body) {
        RoleDAO record = new RoleDAO();
        body.assignTo(record);
        if (body.getType()!=null && body.getType().equals("mc")) {
            roleDAOMapper.clearMC(record);
        }
        roleDAOMapper.updateByPrimaryKeySelective(record);
        return new BaseResponse();
    }

    @Override
    public BaseResponse list(RoleQueryDTO param) {
        int total = roleDAOMapper.total(param);
        List<RoleDAO> list = roleDAOMapper.list(param);
        return new BaseResponse(list, total);
    }
}
